
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form action="/login/" method="post">
    <p>
        {{ obj.username }}
        <span id="uname_error"></span>
    </p>
    <p>
        {{ obj.password }}
        <span id="pwd_error"></span>
    </p>
{#        <input type="submit" value="submit" />#}
    <input type="button" value="AjaxSubmit" onclick="AjaxSubmit();"/>
</form>

<script src="{{ STATIC_URL }}js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
    function AjaxSubmit(){
        $.ajax({
            url: '/login/',
            type: 'POST',
            data: {'username':'','password':''},    //就当提交了一个空数据，制造错误
            success: function(arg){                //arg是返回值，必须是字符串
                var callback_dict = $.parseJSON(arg);
                $('#uname_error').text(callback_dict.username[0].message);
                $('#pwd_error').text(callback_dict.password[0].message);
{#                    console.log(callback_dict.username[0].message)#}
            }
        })
    }
</script>
</body>
</html>